package week5.day33;

import java.util.HashMap;

/**
 * @Author fengzihao
 * @Date 2024-05-17 19:15
 */
public class GetCountUserMapForString {
    public static void main(String[] args) {
        String words = "aababcabcdabcde";
        String wordAndCount = getWordAndCount(words);
        System.out.println("wordAndCount = " + wordAndCount);
    }

    private static String getWordAndCount(String words) {
        HashMap<Character, Integer> characterIntegerHashMap = new HashMap<>();
        String result = "";
        char[] charArray = words.toCharArray();
        for (char c : charArray) {
            characterIntegerHashMap.put(c, characterIntegerHashMap.getOrDefault(c, 0) + 1);
        }
        for (int i = 'a'; i < 'z'; i++) {
            if (characterIntegerHashMap.containsKey((char)i))
                result +=(char)i+"("+characterIntegerHashMap.get((char)i)+")";
        }
        return result;
    }
}
